﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace FloatFall
{
    /// <summary>
    /// 音乐盒
    /// </summary>
    public class MusicBox
    {
        private static MusicBox _ins = null;
        public static MusicBox Instance
        {
            get
            {
                if (_ins == null)
                    _ins = new MusicBox();
                return _ins;
            }
        }

        [DllImport("winmm.dll")]
        public static extern uint mciSendString(string lpstrCommand, string lpstrReturnString, uint uReturnLength, uint hWndCallback);
        public void Play(string filePath)
        {
            mciSendString(@"close temp_alias", null, 0, 0);
            mciSendString(@"open """ + filePath + "\" alias temp_alias ", null, 0, 0);
            mciSendString("play temp_alias repeat", null, 0, 0);
        }

        public void Stop()
        {
            mciSendString("close all", null, 0, 0);
        }
    }
}
